from functools import reduce
from math import factorial

# filter(),map()zip()

# map()
def square(n):
    return n**2
funmap = map(square,list(range(0,10)))
print(list(funmap))

funmap1 = map(lambda x : x**2, list(range(0,10)))
print(list(funmap1))

funmap2 = map(lambda x, y: x + y, [1,2,3,4],[1,2,3,4,])
print(list(funmap2))

# reduce

funreduce1 = reduce(lambda x, y: x+y, ["1","2","3","4","5"],"结果:")
print(funreduce1)

funreduce2 = reduce(lambda x, y: x+y, [1,2,3,4,5])
print(funreduce2)

# filter
funfilter1 = filter(lambda x : x % 2 == 0, list(range(0,10)))
print(list(funfilter1))

# sorted
list01 = [5, -1, 3, 6, -7, 8, -11, 2]
list02 = ['apple', 'pig', 'monkey', 'money']
funsorted1 = sorted(list01)
print(funsorted1)
funsorted2 = sorted(list01,key=abs)
print(funsorted2)
funsorted3 = sorted(list01,key=abs,reverse=True)
print(funsorted3)
funsorted4 = sorted(list02,key=len)
print(funsorted4)


# zip
list01 = ['apple', 'pig', 'monkey', 'money']
list02 = ['apple', 'pig', 'monkey', 'money']
funzip1 = zip(list01,list02)
print(dict(funzip1))

v1 = {1: 11, 2: 22}
v2 = {3: 33, 4: 44}
v3 = {5: 55, 6: 66}
w = zip(*zip(v1, v2, v3))  # 解压
print(list(w))
